package com.hc.model.utils;

import com.hc.DTO.LoginDTO;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class LoginModel {
	public static LoginModel instance;

	public static LoginModel getInstance() {
		if (instance == null)
			instance = new LoginModel();
		return instance;
	}

	public LoginDTO getUserNamePassword(Context context) {
		LoginDTO dto = new LoginDTO();
		String sql = "SELECT * FROM Login";
		DBHelper db = new DBHelper(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			dto.setUserName(c.getString(c.getColumnIndex("userName")));
			dto.setPassWord(c.getString(c.getColumnIndex("Password")));
			dto.setFlag(c.getInt(c.getColumnIndex("flag")));
		}
		c.close();
		db.close();

		return dto;
	}

	public boolean updateLogin(LoginDTO dto, Context context) {
		boolean flag = false;
		// String sql = "UPDATE changelog SET Id=" + id;
		DBHelper db = new DBHelper(context);
		ContentValues values = new ContentValues();
		values.put("userName", dto.getUserName());
		values.put("Password", dto.getPassWord());
		values.put("flag", dto.getFlag());
		flag = db.ExcuteUpdate(null, "Login", values, "1 = 1", null);
		db.close();
		return flag;
	}
}
